/**
 * Created by Administrator on 2017/5/18.
 */
define([
    'regular!./index.html',
    'util/dispatcher/regularModule',
    'pro/cache/node',
], function (template, m, cache) {
    var NodeListModule = Regular.extend({
        template: template,
        data: {
            table: {
                source: [],
                paging: {
                    pageSize: 10,
                    sumTotal: 100,
                    current: 1
                }
            }
        },
        config: function (data) {
            this.cache = cache.NodeCache._$allocate({
                key: 'node-list',
                onlistload: this.listload._$bind(this)
            });

            this.cache._$getList({key: 'node-list'});
        },
        listload: function (options) {
            var data = this.data;
            //console.log(options);
            this.data.table.source = this.cache._$getListInCache(options.key).slice(
                (data.table.paging.current - 1) * data.table.paging.pageSize,
                data.table.paging.pageSize
            );

            data.table.paging.sumTotal = this.cache._$getListInCache(options.key).length;
        },
        select: function (event) {

        },
        onPaging: function(paging) {
            console.log('current data: ', this.data.table.source);
            var data = this.data;
            console.log('data length: ', this.cache._$getListInCache('node-list').length);
            this.data.table.source = this.cache._$getListInCache('node-list').slice(
                (paging.current - 1) * data.table.paging.pageSize,
                (paging.current - 1) * data.table.paging.pageSize + data.table.paging.pageSize
            );
        }
    });
    return m._$regist('node-list', NodeListModule);
});